﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/MasterPage.master" AutoEventWireup="true"
    CodeFile="EventAE.aspx.cs" Inherits="Admin_Modules_Event_EventAE" %>

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
 <script src="/js/jquery.js" type="text/javascript"></script>
    <link type="text/css" rel="Stylesheet" href="/css/Dialog.css" />
    <script src="/js/Editor.js" type="text/javascript"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <%---------------%>
    <div class="header" style="width: 1080px; text-align: left">
        THÊM CHI TIẾT EVENT
        <div class="content-IE">
            <table class="adminContent">
                <tr>
                    <td>
                        Name
                    </td>
                    <td class="adminData">
                        <asp:TextBox runat="server" ID="txtName" Width="500px"/>
                    </td>
                </tr>
                <tr id="tr7" runat="server">
                    <td class="adminTitle">
                        <asp:Label ID="lblEventType" runat="server">Loại event</asp:Label>
                    </td>
                    <td>
                        <asp:DropDownList ID="ddlEventType" runat="server" CssClass="width_a">
                        </asp:DropDownList>
                    </td>
                    <td>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="ddlEventType"
                            runat="server" ErrorMessage="*" ForeColor="Red" InitialValue="-1"></asp:RequiredFieldValidator>
                    </td>
                </tr>
                <tr id="trImage" runat="server">
                    <td class="adminTitle">
                    </td>
                    <td colspan="2">
                        <div style="float: left; width: 80px; height: 80px; border: solid thin orange;">
                            <asp:Image ID="imgThumb" runat="server" EnableViewState="true" AlternateText="Ảnh đại diện"
                                ToolTip="Ảnh đại diện tour" Width="80px" Height="80px" />
                            <asp:HiddenField ID="hdfimgImageTour" runat="server" />
                        </div>
                        <div style="float: left; width: 300px;">
                            &nbsp;
                            <telerik:DialogOpener runat="server" ID="DialogOpener1"></telerik:DialogOpener>
                            <input type="button" id="btnSelectThumb" value="Chọn" style="width: 40px;" onclick="selectThumb()" />
                            <input type="button" id="btnClearThumb" value="Xóa" style="width: 40px;" onclick="clearThumb()" />
                        </div>
                    </td>
                </tr>
                <tr id="tr6" runat="server">
                    <td class="adminTitle">
                        <asp:Label ID="lblIsVisible" runat="server">IsVisible</asp:Label>
                    </td>
                    <td colspan="2">
                        <asp:CheckBox ID="cbIsVisible" runat="server" />
                    </td>
                </tr>
                <tr>
                    <td class="adminTitle">
                        Chi tiết
                    </td>
                    <td class="adminData">
                        <asp:ScriptManager ID="ScriptManager1" runat="server" />
                        <telerik:RadEditor Width="735" Height="500" ID="radEditorContent" ToolsFile="~/App_Data/Xml/DefaultToolbar.xml"
                            runat="server" Skin="Default" EditModes="All" NewLineBr="True" EnableEmbeddedScripts="true"
                            StripFormattingOptions="Css,Font,Span,MSWord,MSWordNoFonts,MSWordRemoveAll" StripFormattingOnPaste="Css,Font,Span,MSWord,MSWordNoFonts,MSWordRemoveAll"
                            ToolbarMode="Default" SpellCheckSettings-AllowAddCustom="false" EnableResize="false"
                            OnClientCommandExecuted="OnClientCommandExecuted" OnClientPasteHtml="OnClientPasteHtml1"
                            ContentFilters="DefaultFilters">
                            <CssFiles>
                                <telerik:EditorCssFile Value="/css/Editor.css" />
                            </CssFiles>
                        </telerik:RadEditor>
                    </td>
                </tr>
            </table>
            <div class="section-header">
                <div class="options">
                    <asp:Button ID="btnSave" runat="server" CssClass="adminButtonBlue" Text="Cập nhật"
                        ToolTip="Save" OnClick="btnSave_Click" />
                    <a href="EventList.aspx" style="cursor: pointer">
                        <input type="button" class="adminButtonBlue" value="Danh sách chi tiết tour" />
                    </a>&nbsp;
                </div>
            </div>
        </div>
        <div class="clear">
        </div>
    </div>
    <%---------------%>
    <script type="text/javascript">
        var regexWhiteSpace = new RegExp("<(p[^>]*)>(((\&nbsp;)*\s*)*)?</p>|<(p[^>]*)><(span[^>]*)>(((\&nbsp;)*\s*)*)?</span></p>|<(font[^>]*)>|<(/font[^>]*)>|<o:p>|</o:p>|<(st1[^>]*)>|<(/st1[^>]*)>|&nbsp;", "gi");
        var regexP = new RegExp("(<p|<P)[^>]*>(.*?)(<\/P>|<\/p>)", "gi");
        var regexOpenDIV = new RegExp("(<div|<DIV)[^>]*>", "gi");
        var regexCloseDIV = new RegExp("(<\/DIV>|<\/div>)", "gi");
        var regexSpan = new RegExp("(<span[^*>]*>)|(<\/span>)|(<SPAN[^*>]*>)|(<\/SPAN>)", "gi");
        /*var regexFont = new RegExp("(<font[^*>]*>)|(<\/font>)|(<FONT[^*>]*>)|(<\/FONT>)", "gi");*/
        var regexFont = new RegExp("(<font|<FONT)[^>]*>(.*?)(<\/FONT>|<\/font>)", "gi");
        var regexStrong = new RegExp("(<strong[^*>]*>)|(<\/strong>)|(<STRONG[^*>]*>)|(<\/STRONG>)", "gi");
        var regexB = new RegExp("(<b|<B)[^>]*>(.*?)(<\/B>|<\/b>)", "gi");
        var regexU = new RegExp("(<u|<U)[^>]*>(.*?)(<\/U>|<\/u>)", "gi");
        var regexI = new RegExp("(<i|<I)[^>]*>(.*?)(<\/I>|<\/i>)", "gi");
        var regexTABLE = new RegExp("(<table|<TABLE)[^>]*>(.*?)(<\/TABLE>|<\/table>)", "gi");
        var regexH1 = new RegExp("(<h1|<H1)[^>]*>(.*?)(<\/H1>|<\/h1>)", "gi");
        var regexH2 = new RegExp("(<h2|<H2)[^>]*>(.*?)(<\/H2>|<\/h2>)", "gi");
        var regexEM = new RegExp("(<em|<EM)[^>]*>(.*?)(<\/EM>|<\/em>)", "gi");
        var regexA = new RegExp("(<a|<A)[^>]*>(.*?)(<\/A>|<\/a>)", "gi");
        var regexUL = new RegExp("(<ul|<UL)[^>]*>(.*?)(<\/UL>|<\/ul>)", "gi");

        function OnClientPasteHtml1(editor, args) {
            var commandName = args.get_commandName();
            var value = args.get_value();

            if (commandName == "Paste") {

                var pasteContent = value;
                pasteContent = pasteContent.replace(regexOpenDIV, "<P>");
                pasteContent = pasteContent.replace(regexCloseDIV, "</P>");
                pasteContent = pasteContent.replace(regexP, "<P>$2</P>").replace(regexWhiteSpace, " ");
                pasteContent = pasteContent.replace(regexSpan, "");
                /*pasteContent = pasteContent.replace(regexFont, "");*/
                pasteContent = pasteContent.replace(regexFont, "$2");
                pasteContent = pasteContent.replace(regexStrong, "");
                pasteContent = pasteContent.replace(regexB, "$2");
                pasteContent = pasteContent.replace(regexU, "$2");
                pasteContent = pasteContent.replace(regexI, "$2");
                pasteContent = pasteContent.replace(regexTABLE, "");
                pasteContent = pasteContent.replace(regexH1, "<P>$2</P>");
                pasteContent = pasteContent.replace(regexH2, "<P>$2</P>");
                pasteContent = pasteContent.replace(regexEM, "$2");
                pasteContent = pasteContent.replace(regexA, "$2");

                pasteContent = pasteContent.replace(/size|SIZE = ([\d]{1})/g, '');

                // plain text
                //if (!pasteContent.match(/(<([^>]+)>)/gi))
                pasteContent = "<P>" + pasteContent + "</P>";

                //set the modified pasted content in the editor
                args.set_value(pasteContent);
            }
        }

        function OnClientCommandExecuted(editor, args) {
            if ("ApplyClass" == args.get_commandName()) {
                var content = editor.get_html(true);
                content = content.replace(/span/gi, "p");
                editor.set_html(content);
            }
        }


        // Insert Image From List Into Editor Content
        Telerik.Web.UI.Editor.CommandList["CustomImageManager"] = function (commandName, radEditorContent, args) {
            var insertImageCallbackFunction = function (sender, args) {
                if (!args.IsCancel) {
                    var html = GetImageAttribute(args);
                    radEditorContent.pasteHtml(html);
                }
            };
            // Indent
            Telerik.Web.UI.Editor.CommandList["CustomerIndent"] = function (commandName, editor, args) {
                editor.pasteHtml('<span style="width:200px;border: 1px dashed #bb0000;background-color: #fafafa;color: blue;"> ' + args.get_value() + ' </span>');
            };

            radEditorContent.showExternalDialog(
            '' + '/Admin/Modules/FileManager/InsertFTPImage.aspx', {},
            800, 620, insertImageCallbackFunction, null, null, true,
            Telerik.Web.UI.WindowBehaviors.Close + Telerik.Web.UI.WindowBehaviors.Move, false, true);
        };

        // Insert Document From List Into Editor Content
        Telerik.Web.UI.Editor.CommandList["CustomDocumentManager"] = function (commandName, radEditorContent, args) {

            var argument = radEditorContent.getSelectionHtml();
            var insertDocumentCallbackFunction = function (sender, args) {
                if (!args.IsCancel) {
                    var html = GetDocumentAttribute(args);
                    radEditorContent.pasteHtml(html);
                }
            };

            radEditorContent.showExternalDialog(
        '' + '/Admin/Modules/FileManager/InsertFTPDocument.aspx', argument,
        780, 550, insertDocumentCallbackFunction, null, null, true,
        Telerik.Web.UI.WindowBehaviors.Close + Telerik.Web.UI.WindowBehaviors.Move, false, true);
        };

        // Flash Video
        Telerik.Web.UI.Editor.CommandList["CustomVideoManager"] = function (commandName, radEditorContent, args) {
            var insertVideoCallbackFunction = function (sender, args) {
                if (!args.IsCancel) {
                    var html = GetVideoAttribute(args);
                    radEditorContent.pasteHtml(html);
                }
            }

            radEditorContent.showExternalDialog(
            '' + '/Admin/Modules/FileManager/InsertVideo.aspx', {},
            800, 620, insertVideoCallbackFunction, null, null, true,
            Telerik.Web.UI.WindowBehaviors.Close + Telerik.Web.UI.WindowBehaviors.Move, false, true);
        };

        // Insert Custom Audio
        Telerik.Web.UI.Editor.CommandList["CustomAudioManager"] = function (commandName, radEditorContent, args) {
            var insertAudioCallbackFunction = function (sender, args) {
                if (!args.IsCancel) {
                    var html = GetAudioAttribute(args);
                    radEditorContent.pasteHtml(html);
                }
            }

            radEditorContent.showExternalDialog(
            '' + '/Admin/Modules/FileManager/InsertAudio.aspx',
            {},
            800,
            620,
            insertAudioCallbackFunction,
            null,
            null,
            true,
            Telerik.Web.UI.WindowBehaviors.Close + Telerik.Web.UI.WindowBehaviors.Move,
            false,
            true);
        };
    </script>
       <script type="text/javascript">

           function selectThumb() {
               var radEditorContent = $find("<%= DialogOpener1.ClientID %>");
               radEditorContent.openUrl("/Admin/Modules/FileManager/InsertFTPImage.aspx", {}, 800, 600, selectThumbComplete, null, "custom link manager", true);
           }

           function clearThumb() {
               $('#<%= imgThumb.ClientID %>').attr("scr", "");
               $('#<%= hdfimgImageTour.ClientID %>').val("");
           }
           var selectThumbComplete = function (sender, args) {
               if (!args.IsCancel) {
                   if (args.Url.length > 0) {
                       var img = document.getElementById("<%= imgThumb.ClientID %>");
                       img.src = args.Url;
                       $('#<%= hdfimgImageTour.ClientID %>').val(args.Url);
                       alert($('#<%= hdfimgImageTour.ClientID %>').val());

                   }
               }
           }

    </script>
</asp:Content>
